#ifndef GRAPHICS_H
#define GRAPHICS_H

#include "EngineApi.h"
#include "D3DVertex.h"
#include <d3dx9math.h>
#include "VertexBufferManager.h"
#include <string>

enum MATRIX_MODES
{
	WORLD_MATRIX = 0,
	VIEW_MATRIX,
	PROYECTION_MATRIX
};

enum PRIM_TYPE
{
	 POINTLIST = D3DPT_POINTLIST,
    LINELIST = D3DPT_LINELIST,
    LINESTRIP = D3DPT_LINESTRIP,
    TRIANGLELIST = D3DPT_TRIANGLELIST,
    TRIANGLESTRIP = D3DPT_TRIANGLESTRIP,
    TRIANGLEFAN = D3DPT_TRIANGLEFAN
};

struct ENGINE_API Texture
{
   std::wstring path;
	float width;
	float height;
	LPDIRECT3DTEXTURE9 data;
};

class ENGINE_API Graphics
{
private:
	LPDIRECT3D9 dxObject;
	LPDIRECT3DDEVICE9 dxDevice;
	LPDIRECT3DVERTEXBUFFER9 pVertexObject; 
	void* pVertexBuffer;

	D3DXMATRIX dxMatrix;
	MATRIX_MODES currentMatrixMode;

	VertexBufferManager<D3DVertex,D3DFVF_XYZ | D3DFVF_DIFFUSE> vertexBufferMgr;
	VertexBufferManager<D3DVertexUV,D3DFVF_XYZ | D3DFVF_TEX1 | D3DFVF_TEXCOORDSIZE2(0)> vertexBufferMgrUV;

	Texture* lastTexture;
public:
	Graphics();
	bool Init(HWND hwnd);
	void Clear();
	void BeginScene();
	void EndScene();
	void Present(HWND hwnd);
	void DeInit();

	void SetMatrixMode(MATRIX_MODES mode);
	void LoadIdentity();
	void Translate(float x, float y, float z);
	void RotateZ(float z);
	void Scale(float x,float y);

	Texture* LoadTexture(std::wstring path, DWORD colorKey);
	void SetTexture(Texture* pTexture);

	bool DrawElements(unsigned int cantidad, D3DVertex* vertices, PRIM_TYPE primType);
	bool DrawSpriteElements(unsigned int cantidad, D3DVertexUV* vertices, PRIM_TYPE primType);
};
#endif // GRAPHICS_H